package api

import (
	"gitee.com/chejiangyi/bsfgo/core/base2"
	"gitee.com/chejiangyi/bsfgo/demo/service/dals"
	"gitee.com/chejiangyi/bsfgo/demo/web/controller/api/http_models"
	"gitee.com/chejiangyi/bsfgo/demo/web/controller/base"
	"github.com/gin-gonic/gin"
)

type TestController struct {
	base.BaseDemoApiController
}

// GetUserSearch 获取图书列表
// @Summary 搜索用户
// @Description 获取系统中的所有用户
// @Tags users
// @Produce json
// @Security ApiKeyAuth
// @Param search body http_models.GetUserSearchRequest true "上传的文件"
// @Success 200 {object} http_models.GetUserSearchResponse[auto_models.User]
// @Failure 200 {object} http_models.GetUserSearchResponse[auto_models.User]
// @Router /test/getUserSearch [post]
func (m *TestController) GetUserSearch(c *gin.Context) {
	defer m.CatchJsonError(c)
	re := &http_models.GetUserSearchRequest{}
	rs := &http_models.GetUserSearchResponse{}
	m.BindRequestJson(c, &re)
	var totalSize int64
	rs.List = dals.DbUserDal.Search(m.GetConn(), re.Name, "", "",
		re.PageIndex, re.PageSize, &totalSize)
	rs.PageTotal = totalSize
	m.JsonSuccess(c, rs)
}

func (m *TestController) GetError(c *gin.Context) {
	panic(base2.NewBsfError("aaa"))
}
